package com.caac.core.config;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright caac 2006</p>
 * <p>Company: caac</p>
 * @author <a href="mailto:project@caac.com.cn">Project Group</a>
 * @version 1.0
 */

public final class AliasHelper {
    public static Alias getAlias(String fullName) {
        String name;
        String prefix = null;
        String parentName = null;
        int index = fullName.lastIndexOf(".");
        if (index != -1) {
            String pre = fullName.substring(0, index);
            String post = fullName.substring(index + 1);
            prefix = pre.replaceAll("\\.", "");
            name = prefix + "." + post;
            index = pre.lastIndexOf(".");
            if (index != -1) {
                parentName = pre.substring(0, index).replaceAll("\\.", "") +
                             "." + pre.substring(index + 1);
            } else {
                parentName = prefix;
            }
        } else {
            name = fullName;
        }
        Alias alias = new Alias();
        alias.setName(name);
        alias.setPrefix(prefix);
        alias.setParentName(parentName);
        return alias;
    }
}
